<?php
namespace app\home\controller;
/*
 *  质押/解押
 * */
use app\common\controller\Home;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use app\common\model\User;

class Pledge extends Home
{
    public function logPage(){
        $address = $this->request->get("address");
        View::assign('address', $address);
        return View::fetch("log_page");
    }

    /*
     *  质押/解押
     * */
    public function loglist(){
        if($this->request->isAjax()){
            $post_data = $this->request->post();
            $page = $post_data['page'] ?? 1;
            $type = $post_data['type'] ?? 1;
            $address = $post_data['address'] ?? '';
            $limit = 15;
            if(!empty($address)){
                $userModel = new \app\common\model\User();
                $uid = $userModel->where("heco_address",$address)->value("id");
            }
            if(empty($uid)){
                return $this->apiResponse(0,'fail');
            }
            $where = [];
            $where[] = ['uid','=',$uid];
            $where[] = ['type','=',$type];
            $lpCashListModel = new \app\common\model\LpCashList();
            $list = $lpCashListModel->where($where)->page($page,$limit)->order("id desc")->field("money,status,c_time")->select()->toArray();
            foreach ($list as $k => $v){
                $list[$k]['c_time'] = date("Y-m-d H:i:s",$v['c_time']);
            }
            $is_bottom = 0;
            if(count($list) < $limit){
                $is_bottom = 1;
            }
            $return_data = [
                'list' => $list,
                'page' => $page,
                'is_bottom' => $is_bottom
            ];
            return $this->apiResponse(1,'success',$return_data);
        }
        return $this->apiResponse(0,'fail');
    }

}